// 左侧展开收起
$('.user_l_dl dt i').click(function(){
    $(this).toggleClass('none1');
    $(this).parents('.user_l_dl').find('dd').slideToggle();
})
// 获取收藏数据
// collectShop
// 封装
function collectShop(){
    var tempData = JSON.parse(localStorage.getItem('collectShop'));
    var temp = '';
    for(var i = 0;i<tempData.length;i++){
        temp+=`
        <li class="user_block_oli">
                                <a href="../page/productDetailsPage.html?${tempData[i].goodid}" >
                                    <img src="${tempData[i].pictureURL}" alt="">
                                    <p>${tempData[i].Hometitle}</p>
                                    <span>¥${tempData[i].HomeZKprice}</span>
                                    <div class="active">查看详情</div>
                                </a>
                                <div class="user_tit">
                                    <a href="" class="guan">关注商品</a>
                                    <a href="javascript:void(0)" class="qu">取消收藏</a>
                                </div>
                                
                                <div class="user_remove">
                                    <div class="user_remove_con">
                                        <div class="user_re_tit">
                                            <a href="" class="tita">✕</a>
                                            <span>提示</span>
                                        </div>
                                        <div class="user_re_con">
                                            <div class="user_re_con_t">
                                                <span></span>
                                                <h3>您确定要取消收藏该商品吗？</h3>
                                            </div>
                                            <div class="user_re_con_y">
                                                <div class="bzd">
                                                    <div class="uyes" data-id="${tempData[i].goodid}">确定</div>
                                                    <div class="uno">取消</div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </li>
        `
    }
    $('.user_block_oul').html(temp);
}
function chushi(){
    if(localStorage.getItem('collectShop')){
        $('.user_block').css({
            'display':'block'
        })
        $('.user_none').css({
            'display':'none'
        })
        collectShop();
        $('.qu').click(function(){
            $(this).parents('.user_tit').next().css({
                'display':'block'
            })
            $('.meng').css({
                'display':'block'
            })
        })
        $('.uyes').click(function(){
            $('.user_remove').css({
                'display':'none'
            })
            $('.meng').css({
                'display':'none'
            })
            var tempPop = JSON.parse(localStorage.getItem('collectShop'));
            var goodid = $(this).data().id;
            for(var i=0;i<tempPop.length;i++){
                if(Number(goodid) == Number(tempPop[i].goodid)){
                    tempPop.splice(i,1);
                    if(tempPop.length == 0){
                        localStorage.setItem('collectShop','');
                    }else{
                        localStorage.setItem('collectShop',JSON.stringify(tempPop));
                    }
                    chushi();
                    break;
                }
            }
            
        })
        $('.uno').click(function(){
            $('.user_remove').css({
                'display':'none'
            })
            $('.meng').css({
                'display':'none'
            })
        })
    }else{
        $('.user_block').css({
            'display':'none'
        }) 
        $('.user_none').css({
            'display':'block'
        })
    }
}
chushi();
